<template>
  <el-dialog
    v-model="visible"
    :title="`新增${form.info_type_name}`"
    width="600px"
    :before-close="handleClose"
  >
    <el-form :model="form" label-width="120px" style="width:88%;" >      
      <el-form-item label="名称">
        <el-input v-model="form.info_name"></el-input>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="form.info_remark" type="textarea" :rows="3"></el-input>
      </el-form-item>
    </el-form>

    <template #footer>
      <span class="dialog-footer">
        <el-button @click="visible = false">关闭</el-button>
        <el-button type="primary" @click="exec">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup >
import { reactive, ref, computed} from "vue";
import { useRouter, useRoute } from "vue-router";
import { tip, get, post, put, del, ddo } from "@/common";

const route = useRoute();





const visible = ref(false);
const open = (type_code,type_name) => {
  form.info_type = type_code;
  form.info_type_name=type_name;
  visible.value = true;
};
const handleClose = (done) => {
  done();
};

const form = reactive({
  info_type: '',
  info_type_name:'',
  info_name: "",
  info_remark:""
});

const emit = defineEmits(["ok"]); 
const exec = ()=>{
    post('/info',form,{title:'提示',message:`您确定提交新${form.info_type_name}吗？`}).then(result=>{
        emit('ok');
        visible.value = false;
        for(let prop in form){
            form[prop] = '';
        }
        console.log(form);
        tip.success(`新增${form.info_type_name}成功！`);
    });
};

defineExpose({ open });


</script>

<style>
</style>